#include<iostream>
#include<vector>
using namespace std;
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
    vector<int> hash;
    vector<bool> visted;
    vector<int> ret;
    int n = nums1.size();
    hash.resize(1000);
    visted.resize(1000);
    for (int e : nums1) {
        hash[e]++;
    }
    for (int x : nums2) {
        if (hash[x] != 0 && visted[x] != true) {
            ret.push_back(x);
            visted[x] = true;
        }
    }
    return ret;
}

int main() 
{
    vector<int> nums1 = { 4,9,5 };
    vector<int> nums2 = { 9,4,9,8,4 };
    vector<int> ret;
    ret  = intersection(nums1, nums2);
    for (int e : ret) 
    {
        cout << e << " ";
    }
    return 0;
 }